'use strict';

var path = require('path'),
    webpack = require('webpack'),
    HtmlwebpackPlugin = require('html-webpack-plugin'),
    CopyWebpackPlugin = require('copy-webpack-plugin'),
    ROOT_PATH = path.resolve(__dirname),
    WEB_PATH = path.resolve(ROOT_PATH, 'site'),
    srcDir = path.resolve(ROOT_PATH, 'src'),
    BUILD_PATH = path.resolve(ROOT_PATH, 'assets'),
    cssDir = path.resolve(ROOT_PATH, 'src/css'),
    antdDir = path.resolve(ROOT_PATH, 'node_modules/antd'),
    pak = require('./package.json');
module.exports = {
  entry: {
    app: path.resolve(srcDir, 'app.jsx'),
    vendors: ['react', 'react-dom', 'redux', 'react-redux', 'react-router', 'react-router-redux', 'redux-thunk', 'redux-logger']
  },
  output: {
    path: path.resolve(BUILD_PATH, 'wap/center'),
    filename: 'js/[name].[hash:8].min.js'
  },
  //babel重要的loader在这里
  module: {
    loaders: [
      {
        test: /\.js|jsx$/,
        loader: 'babel',
        include: srcDir
      },
      {
        test: /\.css?$/,
        loader: 'style!css',
        include: [antdDir,cssDir]
      },
      {
        test: /\.less?$/,
        loader: 'style!css!less',
        include: srcDir
      },
      {
        test: /\.scss?$/,
        loader: 'style!css!sass'
      },
      {
        test: /\.png|.gif$/,
        loader: 'url',
        include: srcDir
      },
      {
        test: /\.svg|woff|eot|ttf$/,
        loader: require.resolve('file-loader') + '?name=[path][name].[ext]'
      }
    ],
    postLoaders: [
      {
        test: /\.jsx?$/,
        loaders: ['es3ify-loader']
      }
    ]
  },
  resolve: {
    extensions: ['', '.js','.jsx', '.css','.less', '.tpl', '.png', '.jpg', '.gif']
  },
  plugins: [
    new CopyWebpackPlugin([{
      from: WEB_PATH,
      to: BUILD_PATH
    }]),
    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendors',
      filename: 'vendors.js'
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false
      }
    }),
    new HtmlwebpackPlugin({
      title: pak.description,
      filename: 'index.html',
      inject: 'body',
      chunks: ['app', 'vendors'],
      template: './src/tmpl/main.html'
    })
  ]
};
/**
 * branches:master
 * */